<?php

namespace backend\models\goods\goods;

use common\models\goods\goods\GoodsStockModel;
use common\models\goods\goods\GoodsModel;
/**
 * Desc 商品库存
 */
class GoodsStock extends GoodsStockModel
{
 
    public static function getUnionAll($condition = [], $page = 1, $page_size = 20, $order_by = 'gt.id DESC', $select = [])
    {
        $bostr = GoodsModel::tableName();
        $query = self::find()->alias('gt')
        ->leftJoin($bostr.' gi', 'gt.gid = gi.id')
        ->select(['gt.*', 'gi.name', 'gi.barcode']);
        list($offset, $limit) = \common\tools\Util::getLimit($page, $page_size);
        if ($condition) {
            $query->where($condition);
        }
        $data['total'] = intval($query->count());
        $query->offset($offset)->limit($limit)->orderBy($order_by);
        $data['list'] = $query->asArray()->all();
        return $data;
    }


}
